@()
@main("Blastn Against Genome-CBGD") {

	<div class="row">
		<div class="form-group col-sm-12">
			<h2 class="page-heading"
			style="text-align: left;
				border-bottom: 5px solid #e9f3f4">Blastn Against Genome</h2>
		</div>
	</div>

	<form class="registration-form form-horizontal" id="form"
	accept-charset="UTF-8" method="post">

		<div class="form-group">
			<label class="control-label col-sm-2">Type of query:</label>
			<div class="col-sm-3">
				<select class="form-control" onchange="change(this)" name="method">
					<option selected value="text">Text</option>
					<option value="file">File</option>
				</select>
			</div>
		</div>

		<div class="form-group" id="queryContent">
			<label class="control-label col-sm-2">Query text:</label>
			<div class="col-sm-8">
				<textarea class="form-control" name="queryText" id="queryText" rows="5"></textarea>
				<span class="help-block">e.g.,&nbsp;<a href="#"><em id="egQuery">
					example</em></a></span>
			</div>
		</div>

		<div id="queryFile" style="display: none;">
			<div class="form-group">
				<label class="control-label col-sm-2">Query fasta file:</label>
				<div class="col-sm-8">
					<input id="input-1" type="file" class="file control-label" name="file" data-show-preview="false"
					data-show-upload="false">
				</div>
			</div>
		</div>

		<div class="form-group">
			<label class="control-label col-sm-2">Database:</label>
			<div class="col-sm-4">
				<select class="form-control"  name="db">
					<option selected value="myDb">Lagenaria siceraria cv. ‘Hangzhou Gourd’</option>
					<option value="otherDb">Lagenaria siceraria cv. USVL1VR-Ls</option>
					<option  value="myDb2">Lagenaria siceraria cv. ‘Hangzhou Gourd’ 2.0</option>
				</select>
			</div>
		</div>

		<div class="form-group">
			<label class="control-label col-sm-2">Evalue:</label>
			<div class="col-sm-2">
				<input class="form-control" name="evalue" id="evalue" value="1e-5">
			</div>

			<label class="control-label col-sm-2">Word size:</label>
			<div class="col-sm-2">
				<input class="form-control" name="wordSize" id="mCharacteristic" value="28">
			</div>

		</div>

		<div class="form-group">
			<label class="control-label col-sm-2">Max target seqs:</label>
			<div class="col-sm-2">
				<input class="form-control" name="maxTargetSeqs" id="mCharacteristic" value="10">
			</div>
		</div>

		<div class="form-group">
			<div class="actions col-sm-offset-2 col-sm-2">
				<button type="button" class="btn btn-primary" style="width: 90%;" id="search" onclick="mySearch()">
					Search</button>
			</div>

			<div class="actions  col-sm-2">
				<button type="reset" class="btn btn-primary" style="width: 90%;">
					Reset</button>
			</div>
		</div>

	</form>

	<div id="result" style="display: none">
		<hr>
		<h4 style="color: black">Result:</h4>
		<div id="resultContent">

		</div>
	</div>

	<script>
			$(function () {
				formValidation()
			})

			function change(element) {
				var value = $(element).find(">option:selected").val()
				if (value == "text") {
					$("#queryContent").show()
					$("#queryFile").hide()
				} else {
					$("#queryContent").hide()
					$("#queryFile").show()
				}
			}

			$('#egQuery').click(function () {
				var eg = ">BG_GLEAN_10000002\n" +
						"GAAGAAGAAGAAGAAAAAGCAAATGGGAAGATTTGTTGCTTACAAGCATTGAAATTTTCCACTTCAAAAATGAGATTAGGAATGGGAAAGAAAAGTGGTTTGAGGAAGATTTCTAAAGCTTTCAAAGGCCTTAAATTGTTGCATCAACTCACTACTAATGGTAAGAACAAGACACATTCTTGA\n"+
						">BG_GLEAN_10000004\n"+
						"GACATCCATGGAACATCAGCCACCGAAGTTGCAGTGAAGTTCGATTGCAGTCCAATAAATCCATGTGTTGGAATAAAGTTAGACGACGTAAGACTTACATATATGAATCAAACCGCCCAAGCTACCTGCAACAATGCAGAAGGGATTGTAGCTAGTCAAGTTCAACCCTCTACTTGCTTCTAG";
				$('#queryText').val(eg);
				$("#form").formValidation("revalidateField","queryText")
			});

			function mySearch() {
				var form = $("#form")
				var fv = form.data("formValidation")
				fv.validate()
				if (fv.isValid()) {
					var form1 = new FormData($("#form")[0]);
					var element = "<div id='content'><span id='info'>Query...</span>&nbsp;<img class='runningImage' src='@routes.Assets.at("images/running2.gif")' style='width: 30px;height: 20px;'></div>"
					var index = layer.alert(element, {
						skin: 'layui-layer-molv'
						, closeBtn: 0,
						title:"Info",
						btn: []
					});
					$.ajax({
						url: "@routes.GenomeToolController.blastGenome()",
						type: "post",
						processData: false,
						contentType: false,
						data: form1,
						success: function (data) {
							layer.close(index)
							if (data.valid == "false") {
								swal("Error", data.message, "error")
								$("#result").hide()
							} else {
							    $("#resultContent").html(data.html)
								$("#result").show()
							}

						}
					});
				}
			}

			function formValidation() {
				var infinityNumber = Number.MAX_VALUE
				$('#form').formValidation({
					framework: 'bootstrap',
					icon: {
						valid: 'glyphicon glyphicon-ok',
						invalid: 'glyphicon glyphicon-remove',
						validating: 'glyphicon glyphicon-refresh'
					},
					fields: {
						queryText: {
							validators: {
								notEmpty: {
									message: 'Query text is required！'
								}
							}
						},
						file: {
							validators: {
								notEmpty: {
									message: 'Query file is required！'
								},
								file: {
									extension: 'txt',
									message: 'Query file must is a txt file！'
								}
							}
						},
						evalue: {
							validators: {
								notEmpty: {
									message: 'Evalue is required！'
								},
								numeric: {
									message: 'Evalue must be number！'
								},
								between: {
									min: "0",
									max: infinityNumber,
									message: "Evalue must greater than or equal to 0！"
								}
							}
						},
						wordSize: {
							validators: {
								notEmpty: {
									message: 'Word size is required！'
								},
								integer: {
									message: 'Word size must be intger！'
								},
								between: {
									min: "4",
									max: infinityNumber,
									message: "Word size must greater than or equal to 4！"
								}
							}
						},
						maxTargetSeqs: {
							validators: {
								notEmpty: {
									message: 'Max target seqs is required！'
								},
								integer: {
									message: 'Max target seqs must be integer！'
								},
								between: {
									min: "0",
									max: infinityNumber,
									message: "Max target seqs must greater than or equal to 0！"
								}
							}
						},
					}
				});
			}

			$("#input-1").fileinput({
				showPreview: false,
			});

	</script>


}